//
//  ShowAllImages.m
//  LanguagesTeach
//
//  Created by Niel Santos on 2/9/13.
//  Copyright 2013 __MyCompanyName__. All rights reserved.
//

#import "IntroductionHelper.h"



@implementation IntroductionHelper

/**
 * Constructor
 * */
- (id)init:  //(Handler mHandler, Context context,
			 //ViewFlipper viewFlipper, 
			 (UILabel*) imageDescription1 
			 imageDescription2: (UILabel*) imageDescription2
		     imageView1: (UIImageView*) imageView1 
			 imageView2: (UIImageView*) imageView2
			 imageCounter: (UILabel*) imageCounter
			 playerPanel: (UIToolbar*) playerPanel 
			 againBtn: (UIBarButtonItem*) againBtn 
			 backBtn: (UIBarButtonItem*) backBtn 
			 playAndPauseBtn: (UIBarButtonItem*) playAndPauseBtn 
			 nextBtn: (UIBarButtonItem*) nextBtn
			 //ActivityDismisser activityDismisser,
			 //SubjectDataSource subjectDataSource
	{
	
		/*
	this.imagesDescription = new TextView[2];
	this.imageViews = new ImageView[2];
	
	this.viewFlipper = viewFlipper;
	this.imagesDescription[0] = imageDescription1;
	this.imagesDescription[1] = imageDescription2;
	this.imageViews[0] = imageView1;
	this.imageViews[1] = imageView2;
	
	// Action buttons
	this.playerPanel = playerPanel;
	this.againBtn = againBtn;
	this.backBtn = backBtn;
	this.playAndPauseBtn = playAndPauseBtn;
	this.nextBtn = nextBtn;
	this.subjectDataSource = subjectDataSource;
	this.imageCounter = imageCounter;
	
	// Initialize treaters
	this.mHandler = mHandler;
	this.audioDelegator = new AudioDelegator(mHandler, this,subjectDataSource);
	this.activityDismisser = activityDismisser;
	
	this.slideAnimator = new SlideAnimator(context, viewFlipper);
		 */
		return nil;
}


/**
 * Enables or disables the icons of buttons
 *
 **/
- (void) refreshButtonsIcons {
	/*
	boolean isFirstSlide;
	boolean isLastSlide;
	
	isFirstSlide = (state.getCurrentFigure() == 0);
	isLastSlide = (state.getCurrentFigure() + 1) == subjectDataSource.getNumberOfEntries();
	
	if (state.getPaused()) {
		playAndPauseBtn.setImageResource(R.drawable.ic_media_play);
		againBtn.setEnabled(false);
	} else {
		playAndPauseBtn.setImageResource(R.drawable.ic_media_pause);
		againBtn.setEnabled(true);
	}
	
	if (isFirstSlide && backBtn.isEnabled()) {
		backBtn.setEnabled(false);
	} else {
		if ((!isFirstSlide) && (!backBtn.isEnabled())) {
			backBtn.setEnabled(true);
		}
	}
	
	if (isLastSlide && nextBtn.isEnabled()) {
		nextBtn.setEnabled(false);
	} else {
		if ((!isLastSlide) && !nextBtn.isEnabled()) {
			nextBtn.setEnabled(true);
		}
	}*/
}

/**
 * Refresh the image and his description
 */
- (void) setImageAndDescription {
	/*
	imageCounter.setText((state.getCurrentFigure() + 1) + "/"
						 + subjectDataSource.getNumberOfEntries());
	imagesDescription[state.getCurrentFigure() % 2]
	.setText(subjectDataSource.getImageDescription(state
												   .getCurrentFigure()));
	imageViews[state.getCurrentFigure() % 2]
	.setImageBitmap(subjectDataSource.getImageView(state
												   .getCurrentFigure()));
	 */
}

/**
 * Print in screen and launch the sound output to some picture
 * 
 */
- (void) doASingleStep {
	/*
	AssetFileDescriptor fd;
	fd = subjectDataSource.getAudioDescriptor(state.getCurrentFigure());
	
	refreshButtonsIcons();
	setImageAndDescription();
	audioDelegator.playAsset(fd);
	 */
}


- (void)setState: (IntroductionState*) state {
	/*this.state = state;
	this.audioDelegator.setUnitInteration(state);
	 */
}


/**
 *	If is running without user interactions will
 *show the slides one by one in an presentation fashion way.
 **/
/*
- (void) run() {
	boolean isLastSlide;
	
	isLastSlide = (state.getCurrentFigure() + 1) == subjectDataSource
	.getNumberOfEntries();
	try {
		state.getLookHumanInteration().acquire();
		if (state.getLastHumanInteractionTimestamp() < state
			.getScheduleTimestamp()) {
			if ((!state.getPaused()) && (!isLastSlide)) {
				state.setCurrentFigure(state.getCurrentFigure() + 1);
				doASingleStep();
				slideAnimator.setAnimationToNextSlide();
				viewFlipper.showNext();
			}else {
				//Last element
				if ((!state.getPaused()) && (isLastSlide)) {
					stop();
				}
			}
		}
		state.getLookHumanInteration().release();
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
}*/

- (void) resume {
	/*
	if(!state.getPaused()){
		audioDelegator.setSheduleMoreEvents(true);
		doASingleStep();
	}*/
}

- (void) pause {
	/*
	try {
		state.getLookHumanInteration().acquire();
		state.setLastHumanInteractionTimestamp();
		if(!state.getPaused()){
			audioDelegator.setSheduleMoreEvents(false);
			audioDelegator.stopAudio();
			mHandler.removeCallbacks(this);
		}
		state.getLookHumanInteration().release();
	} catch (InterruptedException e) {
		e.printStackTrace();
	}*/
}


// Control reload button behavior
- (void) reload {
	/*
	try {
		state.getLookHumanInteration().acquire();
		state.setLastHumanInteractionTimestamp();
		if(!state.getPaused()){
			mHandler.removeCallbacks(this);
			audioDelegator.replayLastAsset();
		}
		state.getLookHumanInteration().release();
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
	 */
}

/*
 * Control previous button behavior
 */
- (void) previous {
	/*
	boolean onFirstSlide;
	
	onFirstSlide = (state.getCurrentFigure() == 0);
	try {
		state.getLookHumanInteration().acquire();
		if(!onFirstSlide){
			state.setLastHumanInteractionTimestamp();
			if(!state.getPaused()){
				mHandler.removeCallbacks(this);
				audioDelegator.stopAudio();
			}
			state.setCurrentFigure(state.getCurrentFigure()-1);
			doASingleStep();
			slideAnimator.setAnimationToPreviousSlide();
			viewFlipper.showPrevious();
		}
		state.getLookHumanInteration().release();
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
	*/
}


/**
 * Control play/pause button behavior
 */
- (void) playAndPause {
	/*
	try {
		state.getLookHumanInteration().acquire();
		state.setLastHumanInteractionTimestamp();
		if(state.getPaused()){
			state.setPaused(false);
			doASingleStep();
		}else{
			state.setPaused(true);
			mHandler.removeCallbacks(this);
			audioDelegator.stopAudio();
			refreshButtonsIcons();
		}
		state.getLookHumanInteration().release();
	} catch (InterruptedException e) {
		e.printStackTrace();
	}*/
}

/**
 * Go to the next picture se estiver no ultimo salta fora look o humanAction
 * se estiver pausado acrescenta o contador e adiciona um ao currentFigure
 * senao mete o human action a um acrescenta o contador e adiciona um ao
 * currentFigure exetuda um passo releasa o humanAction
 * */
- (void) forward {
	/*
	boolean isLastSlide;
	isLastSlide = (state.getCurrentFigure() + 1) == subjectDataSource.getNumberOfEntries();
	try {
		state.getLookHumanInteration().acquire();
		if(!isLastSlide){
			state.setLastHumanInteractionTimestamp();
			if(!state.getPaused()){
				mHandler.removeCallbacks(this);
				audioDelegator.stopAudio();
			}
			state.setCurrentFigure(state.getCurrentFigure()+1);
			doASingleStep();
			slideAnimator.setAnimationToNextSlide();
			viewFlipper.showNext();
		}
		state.getLookHumanInteration().release();
	} catch (InterruptedException e) {
		e.printStackTrace();
	}*/
}

/**
 * faz look do human action coloca o human action a um remove chamadas.
 * coloca o audio no ultimo frame releasa o human action
 */
- (void) stop {
	/*
	viewFlipper.startAnimation(slideAnimator.getOutToUp());
	activityDismisser.onBackPressed();
	 */
}

/** Hide options available on player menu */
- (void) hidePlayerMenu{
	/*
	if (playerPanel.getVisibility() != View.GONE) {
		playerPanel.setVisibility(View.GONE);
	}
	 */
}

- (void) showPlayerMenu{
	/*
	playerPanel.setVisibility(View.VISIBLE);
	float yTranslationBackup = playerPanel.getTranslationY();
	playerPanel.setTranslationY(playerPanel.getHeight());
	playerPanel.setTranslationY(yTranslationBackup);
	 */
}



/**
 * If the menu is visible hide if is hidden show
 */
- (void) showAndHidePlayerMenu {
	/*
	if (playerPanel.getVisibility() == View.GONE) {
		showPlayerMenu();
	} else {
		hidePlayerMenu();
	}*/
}


@end
